package com.shelpe.services.sinbad.entity.mongo;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.sinbad.controller.dto.EffectDto;
import com.shelpe.services.sinbad.entity.jpa.User;
import com.shelpe.services.sinbad.utils.DateUtil;

import lombok.Data;

@Data
@Document(collection = "business_cost_rtr")
public class BusinessCostRtr {
	@Id
	private String id;
	@Indexed
	private long userID;
	@Indexed
	private String type;// manual,auto
	@Indexed
	private int minute;
	@Indexed
	private Date date;

	private Date logDate;
	private EffectDto metric;

	public BusinessCostRtr() {
		this.setLogDate(DateUtil.parseDate2date(DateFormatUtils.format(new Date(), "yyyy-MM-dd")));
	}

	public void from(User user, Date date, int time, String type) {
		this.userID = user.getUserID();
		this.minute = time;
		this.date = date;
		this.id = DateFormatUtils.format(this.date, "yyyy-MM-dd HH:mm") + "_" + this.userID;
		this.setType(type);
	}

}
